<?php
/**
 * Created by PhpStorm.
 * User: Monkey
 * Date: 2021/10/13
 * Time: 11:27
 * Desc: 框架
 */
declare (strict_types=1);

namespace app\backend\controller;

use app\backend\base\controller\Base;
use app\extend\model\Auth;

class Index extends Base
{
    /**
     * 框架主体
     */
    public function index()
    {
        //获取角色拥有的菜单
        $authArr = Auth::where([
            ['role_id', '=', session('role_id')]
        ])->field('menu_id')->select()->toArray();

        $menuIdArr = array_column($authArr, 'menu_id');

        //获取菜单
        $menuArr = \app\extend\model\Menu::where([
            ['id', 'in', $menuIdArr],
            ['type', '=', 0]
        ])->order(['sort' => 'asc','id' => 'asc'])->select()->toArray();

        foreach ($menuArr as &$menuVal) {
            $menuVal['url'] = $menuVal['c'] . '/' . $menuVal['a'];
        }

        return view('index', ['menu_list' => findTree($menuArr)]);
    }

    /**
     * 切换模板
     */
    public function theme()
    {
        return view('theme');
    }

    /**
     * 锁屏
     */
    public function lock()
    {
        return view('lock');
    }

    /**
     * 获取提现待处理数量
     */
    public function getWithdrawCount()
    {
        $count = \app\extend\model\Withdraw::where(['status' => 0])->count();

        return json(_S('获取成功',[
            'count' => $count
        ]));
    }

    /**
     * 获取充值待处理数量
     */
    public function getRechargeCount()
    {
        $count = \app\extend\model\Recharge::where(['status' => 0])->count();

        return json(_S('获取成功',[
            'count' => $count
        ]));
    }

    /**
     * 获取订单数量
     */
    public function getOrderCount()
    {
        $where = [
            ['buytime','between',[date('Y-m-d'),date('Y-m-d 23:59:59')]]
        ];

        $count = \app\extend\model\Order::where($where)->count();

        return json(_S('获取成功',[
            'count' => $count
        ]));
    }
}
